package com.atguigu.springcloud.alibaba.dao;

import com.atguigu.springcloud.alibaba.domain.Order;
import org.apache.ibatis.annotations.*;

@Mapper
public interface OrderDao {

    //1 新建订单
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("insert into t_order(user_id,product_id,count,money,status) " +
            "values(#{userId},#{productId},#{count},#{money},0)")
     Long createOrder(Order order);

    //2 修改订单状态
    @Update("update t_order set status=1 where id = #{id} and status = #{status}")
    void updateStatus(@Param("id") Long id, @Param("status") Integer status);

    @Select("select * from t_order where id = #{id}")
    @Results(id = "orderMap",
            value = {
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "userId",column = "user_id"),
            @Result(property = "productId",column = "product_id"),
            @Result(property = "count",column = "count"),
            @Result(property = "money",column = "money"),
            @Result(property = "status",column = "status"),
            }
    )
    Order getById(Integer id);
}
